import java.sql.Timestamp;
import java.util.Calendar;
import java.util.List;
import base.*;


public class UpdateThread extends Thread{
	
	private int time ;
	private int step ;
	
	public UpdateThread(int time, int step) {
		this.time = time;
		this.step = step;
	}
	
	public void run(){
		DataTracker d = new DataTracker();
		List<Peer> peers;
		while(true){
			d.createEm();
			Timestamp now = new Timestamp(Calendar.getInstance().getTime().getTime());
			peers = d.listPeers();
			for(Peer p: peers){
				if(now.getTime() - p.getTime().getTime() > time){
					d.deleteShares(p);
					d.deletePeer(p);					
				}				
			}
			d.closeEm();
			try {
				Thread.currentThread().sleep(step);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
}